﻿#include"Bag.h"
#include<iostream>
#include<iomanip>
using namespace std;
Bag::Bag():Wpn_hand(0),Armor_body(16) {
	//volume = 30;
	//leftv = 30;
	for (int i = 0; i < 22; i++) {
		items[i].id = i;
		items[i].num = 0;
	}
	money = 100;

}
Bag::Bag(int m) :Wpn_hand(0), Armor_body(16) {
	//volume = 30;
	//leftv = 30;
	for (int i = 0; i < 22; i++) {
		items[i].id = i;
		items[i].num = 0;
	}
	money = m;

}
void Bag::setmoney(int m) {
	money = m;
}
int Bag::getmoney() const {
	return money;
}
void Bag::addGoods(int id, int num) {
	items[id].num += num;
	
}
void Bag::reduceGoods(int i,int num) {
	if (items[i].num == 0) {
		cout << "无法售出" << endl;
	}
	else {
		items[i].num -= num;
		items[i].num = items[i].num < 0 ? 0 : items[i].num;
	}
	
}
void Bag::showbag() {
	int i = 0;
	string name;
	cout << setw(10) << "序号" << setw(10) << "名称"<<"   " << "剩余数量" << endl;
	while (i<22) {
		if (items[i].num != 0) {
			if (items[i].id < 10)
				name = wpn[items[i].id].getname();
			else if (items[i].id < 16)
				name = drug[items[i].id - 10].getname();
			else
				name = armor[items[i].id - 16].getname();
			cout << setw(10) << i << setw(10) << name << "   " << items[i].num << endl;
		}
		i++;
		}
	cout << "当前武器：" << Wpn_hand.getname() << endl;
	cout << "当前防具：" << Armor_body.getname() << endl;
	cout << "金钱:" << money<<"$"<<endl;
	}
void Bag::useWpn() {
	cout << "请输入武器id" << endl;
	int in;
	cin >> in;
		if (in >= 0 && in < 10) {
			if (items[in].num == 0) {
				cout << "并未拥有该武器！" << endl;
			}
			else {
				int id = Wpn_hand.getid();
				Wpn_hand = wpn[in];
				items[in].num--;
				items[id].num++;
				cout << "使用成功!" << endl;
			}
		}
		else {
			cout << "非法的武器id！" << endl;
		}
}
double Bag::useArmor() {
	cout << "请输入防具id" << endl;
	int in;
	cin >> in;
	if (in >= 16 && in < 22) {
		if (items[in].num == 0) {
			cout << "并未拥有该防具！" << endl;
			return 0;
		}
		else {
			int id = Armor_body.getid();
			double maxHp=Armor_body.getadd_mp();
			Armor_body = armor[in-16];
			items[in].num--;
			items[id].num++;
			cout << "使用成功!" << endl;
			return Armor_body.getadd_mp() - maxHp;
		}
	}
	else {
		cout << "非法的防具id！" << endl;
		return 0;
	}
}
int Bag::getGoodsnum(int i) const{
	return items[i].num;
}
double Bag::getAddAtk() const {
	return Wpn_hand.getaddatk();
}
int Bag::getDf() const{
	return Armor_body.getadd_df();
}
int Bag::getAddHp() const{
	return Armor_body.getadd_mp();
}
int Bag::getWpn() {
	return Wpn_hand.getid();
}
int Bag::getArmor() {
	return Armor_body.getid();
}
void Bag::setWpn(int id) {
	Wpn_hand = wpn[id];
}
void Bag::setArmor(int id) {
	Armor_body = armor[id - 16];
}